#-*- coding:utf-8 -*-
from selenium import webdriver
import unittest
import  uniout




class login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.get("https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F%3Fcu%3Dtrue%26utm_source%3Dbaidu-pinzhuan%26utm_medium%3Dcpc%26utm_campaign%3Dt_288551095_baidupinzhuan%26utm_term%3D0f3d30c8dba7459bb52f2eb5eba8ac7d_0_f96bb5f6af3a4b659b87e65dd4282e76")
        self.driver.implicitly_wait(10)

        self.login_tab_r =self.driver.find_element_by_class_name("login-tab-r")
        self.loginname= self.driver.find_element_by_id("loginname")
        self.nloginpwd=self.driver.find_element_by_id("nloginpwd")
        self.loginsubmit=self.driver.find_element_by_id("loginsubmit")

        self.login_box =self.driver.find_element_by_class_name("login-box")
        self.qrcode_ogin =self.driver.find_element_by_class_name("qrcode-login")



        pass
    def tearDown(self):
        self.driver.quit()

        pass
    def test_us_nome_ps_nome(self):
        u"""账号不为空，密码不为空，密码错误！！！"""
        self.login_tab_r.click()

        self.loginname.send_keys(u"会计师快递费")
        self.nloginpwd.send_keys("51624")

        self.loginsubmit.click()

        self.driver.implicitly_wait(5)

        self.msg=self.driver.find_element_by_class_name("msg-error")
        self.text=self.msg.text

        self.assertAlmostEqual(self.text,u"你的账号因安全原因被暂时封锁，请将账号和联系方式发送到shensu@jd.com，等待处理")
    def test_us_nome_ps_em(self):
        u"""用户名为空,密码为空,应该提示请输入用户名"""
        self.login_tab_r.click()
        if self.login_box.is_displayed() ==True:
            self.loginname.clear()
            self.nloginpwd.clear()
            self.loginsubmit.click()

            self.msg = self.driver.find_element_by_class_name("msg-error")
            self.text=self.msg.text

            self.assertAlmostEqual(self.text,u"请输入账户名和密码")
        else:
            u"""用户名div不可见,网络原因造成"""
            self.assertEqual(self.login_box.is_displayed(), "True")
        pass
    def test_logr_img(self):
        u"""logo点击"""
        self.logeimg=self.driver.find_element_by_xpath("//div[@id = 'logo']/a/img")
        self.logeimg.click()
        self.driver.implicitly_wait(30)
        self.title=self.driver.title
        self.assertAlmostEqual(self.title,u"京东(JD.COM)-正品低价、品质保障、配送及时、轻松购物！")

    def test_research(self):
        u"""调查问卷"""
        self.qlink=self.driver.find_element_by_link_text("登录页面，调查问卷")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"登录页满意度调查")


    def test_loge_about(self):
        u"""关于我们"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[1]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"企业简介-京东商城")

    def test_loge_contact(self):
        u"""联系我们"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[2]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"联系我们-京东商城")
    def test_loge_personnel(self):
        u"""人才招聘"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[3]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"京东招聘官网")

    def test_loge_business(self):
        u"""商家入驻"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[4]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"商家入驻-入驻流程 - 京东全品类专题活动-京东")

    def test_loge_advertisement(self):
        u"""广告服务"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[5]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"广告服务 - 京东全品类专题活动-京东")
    def test_loge_ipono(self):
        u"""手机京东"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[6]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"手机京东 - 京东")
    def test_loge_friendship(self):
        u"""友情链接"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[7]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"友情链接")
    def test_loge_sale(self):
        u"""销售联盟"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[8]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"京东联盟")
    def test_loge_community(self):
        u"""京东社区"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[9]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"京东社区 - 京东电脑、办公|游戏设备专题活动-京东")
    def test_loge_welfare(self):
        u"""京东公益"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[10]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, u"京东公益")
    def test_loge_english(self):
        u"""Eglish"""
        self.qlink=self.driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/a[11]")
        current_window = self.driver.current_window_handle
        self.qlink.click();
        self.driver.implicitly_wait(30)
        all_windows = self.driver.window_handles
        for window in all_windows:
            if current_window != window:
                self.driver.switch_to_window(window)
                self.rearch = self.driver.title
                self.assertEqual(self.rearch, "JD.com Global Online Shopping Site: Online Shopping for Electronics, Clothing, Toys and More")











